import requests
import hashlib
import json
import csql
saccount = '2019141460196'
spassword = b'035619'
headers ={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'}
base_url = 'http://47.108.67.131/timetable_api/v1/'


def get_table(account, password ):
    md5passwd = hashlib.md5(password)
    url = base_url +'timetables'+ '?account=' + account + '&password=' + md5passwd.hexdigest()
    response = requests.get(url,headers=headers)
    #print(url)
    return response


def get_course(classname):
    url1 = base_url + 'courses' + '?course_name=' + classname
    re=requests.get(url1,headers=headers)
    return re


def parses(raw):
    return json.loads(raw)


def main():
    html = get_table(saccount,spassword).text
    with open("kebiao.html",'w',encoding='utf-8') as f:
        f.write(html)
    data = parses(html)
    #print(data['xkxx'])
    for i in data['xkxx'][0]:
        csql.store(data['xkxx'][0][i],saccount)
        #print(data['xkxx'][0][i])
def main1():
    data= get_course()
    js=data.json()
    for i in js:
        if(i['kcm']=='Python基础及应用'):
            print(i)

if __name__ == '__main__':
    main()
